package com.thor.palmmall.rest.hdmall.media.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.springframework.beans.factory.annotation.Autowired;

import com.thor.commons.exception.ThorServiceException;
import com.thor.commons.util.Assert;
import com.thor.palmmall.hdmall.media.HDMMediaService;
import com.thor.palmmall.rest.hdmall.media.MMediaService;

/**
 * @author:liyang
 * @time:2017年7月25日 下午4:13:44
 * @since:1.0
 */
public class MMediaServiceImpl implements MMediaService {

  @Override
  public List<String> upload(Attachment attachment) throws ThorServiceException {

    Assert.assertArgumentNotNull(attachment, "attachment");
    return hdmMediaService.upload(attachment);

  }
  //
  // @Override
  // public Response download(String moduleName, String num, String fileName)
  // throws ThorServiceException {
  //
  // Assert.assertArgumentNotNull(moduleName, "moduleName");
  // Assert.assertArgumentNotNull(num, "num");
  // Assert.assertArgumentNotNull(fileName, "fileName");
  //
  // try {
  // byte[] byteArr = hdmMediaService.download(moduleName, num, fileName);
  // File file = new File("/Users/liyang/Desktop/pic/ic_error_tip.png");
  //
  // FileCopyUtils.copy(byteArr, file);
  // return Response.ok(file).build();
  // } catch (Exception e) {
  // throw new ThorServiceException(e);
  // }
  // }

  @Autowired
  HDMMediaService hdmMediaService;

  @Override
  public List<String> uploadList(List<Attachment> attachments) throws ThorServiceException {
    Assert.assertArgumentNotNull(attachments, "attachments");
    List<String> result = new ArrayList<String>();
    for (Attachment att : attachments) {
      result.addAll(upload(att));
    }
    return result;
  }
}
